const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require("copy-webpack-plugin")



module.exports = {
  entry: path.resolve(__dirname, '../src/index.js'),
  output: {
    path: path.resolve(__dirname, '../bulid'),
    filename: './js/main.js',
    publicPath: "/"
  },
  plugins: [
    //生成html文件,需要先设置对应的参照模板
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, '../public/index.html'),
      filename: "index.html",
    }),
    //打包公共资源
    new CopyWebpackPlugin({
      patterns: [{
        from: path.resolve(__dirname, '../public'),
        to: "public",
        globOptions: {
          ignore: ["**/index.html"]
        }
      }],
    })
  ],
  //配置路径别名
  resolve: {
    alias: {
      $v: path.resolve(__dirname, "../src/views"),
      $r: path.resolve(__dirname, "../src/routes"),
      $a: path.resolve(__dirname, "../src/api"),
    },
    extensions: [".js", ".json", ".ejs"],
  },
  //加载器
  module: {
    //   rules: [{
    //     test: /\.html$/i,
    //     use: [
    //         'html-loader'
    //     ]
    // }]
    rules: [
      //......
      {
        test: /\.ejs$/,
        loader: 'ejs-loader',
        options: {
          variable: 'data', // 可以在模块当中使用data进行数据处理
        }
      },
      {
        test: /\.css$/i,
        use: [
          //use中loader加载是有顺序的，先下后上，注意有的loader需要按照顺序书写
          "style-loader",
          'css-loader'
        ]
      }],
  },
  mode: 'production'
}